import 'package:flutter/material.dart';
import 'package:flutter_fitness/app_controller.dart';
import 'package:flutter_fitness/component/home_card.dart';
import 'package:get/get.dart';

import 'home_logic.dart';

class HomePage extends StatelessWidget {
  final HomeLogic logic = Get.put(HomeLogic());

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: [
        Padding(
          padding: EdgeInsets.only(top: 12, left: 20),
          child: GetBuilder(
            builder: (AppController controller) {
              return Text(
                "Hello,\n${controller.user.value.username}.",
                style: TextStyle(fontWeight: FontWeight.bold, fontSize: 50),
              );
            },
          ),
        ),
        Container(
          margin: EdgeInsets.all(20),
          height: 50,
          decoration: BoxDecoration(
              color: Color.fromARGB(255, 240, 240, 240),
              borderRadius: BorderRadius.all(Radius.circular(5))),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Padding(
                padding: EdgeInsets.only(left: 14),
                child: Icon(Icons.info_outlined),
              ),
              Padding(
                padding: EdgeInsets.only(left: 10),
                child: Obx(() => Text(
                  "你目前总共打卡${logic.count.value}天",
                  style: TextStyle(fontSize: 18, fontWeight: FontWeight.w300),
                )),
              ),
            ],
          ),
        ),
        Padding(
          padding: EdgeInsets.only(left: 20, bottom: 10),
          child: Text(
            "Today",
            style: TextStyle(
                color: Color.fromARGB(255, 149, 149, 149),
                fontWeight: FontWeight.w700),
          ),
        ),
        Wrap(
          alignment: WrapAlignment.start,
          children: [
            GetBuilder(builder: (AppController controller) {
              return HomeCard(
                  color: Colors.black,
                  title: Text(
                    "今日步数",
                    style: TextStyle(color: Colors.white, fontSize: 15),
                  ),
                  content: Text(
                    "${controller.record.value.step}步",
                    style: TextStyle(
                        color: Colors.white,
                        fontSize: 30,
                        fontWeight: FontWeight.bold),
                  ),
                  icon: Icon(
                    Icons.map,
                    color: Colors.white,
                    size: 20,
                  ));
            }),
            GetBuilder(builder: (AppController controller) {
              return HomeCard(
                  color: Color(0xFF3711FE),
                  title: Text(
                    "今日体重",
                    style: TextStyle(color: Colors.white, fontSize: 15),
                  ),
                  content: Text(
                    controller.record.value.weight == -1 ? "未记录": "${controller.record.value.weight}斤",
                    style: TextStyle(
                        color: Colors.white,
                        fontSize: 30,
                        fontWeight: FontWeight.bold),
                  ),
                  icon: Icon(
                    Icons.sports_handball_sharp,
                    color: Colors.white,
                    size: 20,
                  ));
            }),
            GetBuilder(builder: (AppController controller) {
              return HomeCard(
                  color: Color(0xFF7760CF),
                  title: Text(
                    "是否祷告",
                    style: TextStyle(color: Colors.white, fontSize: 15),
                  ),
                  content: Text(
                    controller.record.value.isPray ? "是": "否",
                    style: TextStyle(
                        color: Colors.white,
                        fontSize: 30,
                        fontWeight: FontWeight.bold),
                  ),
                  icon: Icon(
                    Icons.clean_hands_sharp,
                    color: Colors.white,
                    size: 20,
                  ));
            }),
            GetBuilder(builder: (AppController controller) {
              return HomeCard(
                  color: Color(0xFF4292F8),
                  title: Text(
                    "是否读经",
                    style: TextStyle(color: Colors.white, fontSize: 15),
                  ),
                  content: Text(
                    controller.record.value == null ? "否" : (controller.record.value.isRead ? "是": "否"),
                    style: TextStyle(
                        color: Colors.white,
                        fontSize: 30,
                        fontWeight: FontWeight.bold),
                  ),
                  icon: Icon(
                    Icons.book,
                    color: Colors.white,
                    size: 20,
                  ));
            }),
          ],
        )
      ],
    );
  }
}
